<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
		<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
		<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
	<style>
		@font-face {
		  font-family: 'iconfont';  /* project id 416894 */
		  src: url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.eot');
		  src: url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.eot?#iefix') format('embedded-opentype'),
		  url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.woff') format('woff'),
		  url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.ttf') format('truetype'),
		  url('http://at.alicdn.com/t/font_416894_vy1ju04z9ofxbt9.svg#iconfont') format('svg');
		}

		nav{
			font-family: "iconfont" !important;
		}
	</style>
</head>
<body>

<nav class="navbar navbar-default navbar-fixed-top" style="font-family: 'iconfont' !important; background: #fff; box-shadow: 0px 2px 5px #888888;">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="index.html">点滴</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      
      
      <ul class="nav navbar-nav navbar-right">
      	<div class="navbar-form navbar-left">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="搜索">
        </div>
        <button type="submit" class="btn btn-default">&#xe6a7;</button>
        
      </div>

        <li class="dropdown">
          <a id="nav_user_menu" href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="padding-top: 8px;padding-bottom: 8px;">
          	<span><img id="nav_head_img" src="" style="width: 32px; height: 32px; background: #000;"></span>
          	<span id="nav_nickname">nickname</span>
          	<span class="caret"></span>
          </a>
          <ul class="dropdown-menu">
            <li><a href="data_alter.html?t=0">&#xe603; 修改资料</a></li>
            <li><a href="data_alter.html?t=1">&#xe69f; 修改头像</a></li>
            <li><a href="data_alter.html?t=2">&#xe61d; 修改密码</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="javascript:;" id="logout_link">&#xe60d; 退出登录</a></li>
          </ul>
        </li>

        <li id="nav_login" style="margin-right: 8px;">
        	<button type="button" class="btn btn-default navbar-btn" id="nav_login_btn">登录</button>
        	<button type="button" class="btn btn-default navbar-btn" id="nav_reg_btn">注册</button>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

<script>
	$(document).ready(function(){
		loadUserInfo();
	})

	function loadUserInfo(){
		$.get('userinfo.do', function(data){
			try{
				var jsonObj = JSON.parse(data);
				if (jsonObj.error == 0) {
					var thisData = jsonObj.data;
					var head_img = 'img/head/' + thisData.head_image + ".jpg";
					$("#nav_head_img").attr("src", head_img);
					$("#nav_nickname").html(thisData.nickname);

					$("#nav_user_menu").show();
					$("#nav_login").hide();
				}else if (jsonObj.error == 220) {
					// window.location.href = "login.html";
					$("#nav_user_menu").hide();
					$("#nav_login").show();

				}else{
					alert(jsonObj.msg);
				}
			}catch(ex){
				alert(ex);
			}
		})
	}

	$("#nav_login_btn").click(function(){
		window.location.href = "login.html";
	})
	$("#nav_reg_btn").click(function(){
		window.location.href = "register.html";
	})
	$("#logout_link").click(function(){
		// console.log('logout');
		$.get('logout.do', function(data){
			try{
				var jsonObj = JSON.parse(data);
				if (jsonObj.error == 0) {
					window.location.href = "login.html";
				}
			}catch(ex){
				console.log(ex);
			}
		})
	})

</script>

</body>
</html>